package com.pz.memberunit.controller;

import com.pz.art.domain.AssoEvents;
import com.pz.art.service.EventsService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/unit")
public class UnitEventsController extends BaseController {

    @Autowired
    private EventsService assoEventsService;

    /**
     * 获取单位活动
     */
    @PreAuthorize("@ss.hasPermi('unit:getunitevents')")
    @GetMapping(value = "/getunitevents")
    public TableDataInfo getInfo()
    {
        startPage();
        List<AssoEvents> list = assoEventsService.getEventsByUnitId(getUserId());
        return getDataTable(list);

    }

    /**
     * 新增活动
     */
    @PreAuthorize("@ss.hasPermi('unit:add:unit:events')")
    @Log(title = "活动", businessType = BusinessType.INSERT)
    @PostMapping("/add/unit/events")
    public AjaxResult add(@RequestBody AssoEvents assoEvents)
    {
        System.out.println(assoEvents);
        return toAjax(assoEventsService.addunitevents(assoEvents,getUserId()));
    }

//    /**
//     * 报名活动
//     */
//    @PreAuthorize("@ss.hasPermi('unit:apply:unit:events')")
//    @Log(title = "活动", businessType = BusinessType.INSERT)
//    @PostMapping("/apply/unit/events")
//    public AjaxResult apply(@RequestBody AssoApply assoApply)
//    {
//        return toAjax();
//    }

    /**
     * 获取所有可参与报名的活动
     */
    @PreAuthorize("@ss.hasPermi('unit:apply:unit:events')")
    @GetMapping("/apply/unit/events")
    public TableDataInfo getapplyevents(AssoEvents assoEvents){
        startPage();
        System.out.println(assoEventsService.selectApplyAssoEventsList(assoEvents, getUserId()));
        List<AssoEvents> list = assoEventsService.selectApplyAssoEventsList(assoEvents, getUserId());
        return getDataTable(list);
    }

    /**
     * 活动添加参赛人员
     */
    @PreAuthorize("@ss.hasPermi('unit:apply:unit:events')")
    @Log(title = "活动", businessType = BusinessType.INSERT)
    @GetMapping("/apply/unit/memberevents")
    public AjaxResult applyadd(@RequestParam List<Long> events_ids, @RequestParam Map<String,String> unit_member_id)
    {
        AjaxResult ajaxResult = new AjaxResult();
        assoEventsService.addonAssortments(unit_member_id);
        return success();
    }

}
